package com.example.Service;

import com.example.Entity.Student;
import com.example.Mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @version: java version 23
 * @Author: 韩学新
 * @description:
 * @date: 2025-05-18 下午3:05
 */
public class StudentService {
    public static void main(String[] args) throws IOException {

        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory =
                new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

//        List<Student> students = sqlSession.selectList("getAllStudent");
        StudentMapper mapper = sqlSession.getMapper(StudentMapper.class);


//        List<Student> students = mapper.getAllStudent2();
//        System.out.println(students);
//        Student student = mapper.getStudentById(1L);
//        System.out.println(student);
        /**
         * 增删改操作需要手动提交事务
         */
//        int i = mapper.deleteStudentById(3L);
//        sqlSession.commit();

        List<Student> students = mapper.getStudentByName("huawei");
        System.out.println(students);

        sqlSession.close();

    }
}
